//
//  ShowMoreCollectionViewCell.m
//  WWAVPlayer
//
//  Created by dllo on 15/10/29.
//  Copyright © 2015年 LZY. All rights reserved.
//

#import "ShowMoreCollectionViewCell.h"
#import "ShowMore_TBV_Cell.h"
#import "Blocks.h"
#import "Show_Button_ViewController.h"
@implementation ShowMoreCollectionViewCell

/*
 // Only override drawRect: if you perform custom drawing.
 // An empty implementation adversely affects performance during animation.
 - (void)drawRect:(CGRect)rect {
 // Drawing code
 }
 */
- (void)passToCollectionWithIdNum:(NSString *)idNum
{
    [self.delegate passToMainControllerWithIdNum:idNum];
}

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        self.headView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 375 * W, 60 * H)];
        self.headView.backgroundColor = [UIColor colorWithWhite:0.937 alpha:1.000];
        //**
        self.button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
        [_button setTitle:@"查看全部 >" forState:UIControlStateNormal];
        [_button setTintColor:[UIColor whiteColor]];
        _button.frame = CGRectMake(10 * W, 10 * H, 355 * W, 40 * H);
        _button.backgroundColor = [UIColor orangeColor];

        [self.headView addSubview:_button];
        
        self.tableView = [[UITableView alloc]initWithFrame:self.bounds style:UITableViewStylePlain];
        self.tableView.backgroundColor = [UIColor grayColor];
        self.tableView.delegate = self;
        self.tableView.dataSource = self;
        self.tableView.tableHeaderView = self.headView;
        [self addSubview:self.tableView];
        
    }
    return self;
}

- (void)layoutSubviews
{
    [super layoutSubviews];
    [self.button addTarget:self action:@selector(butClicked:) forControlEvents:UIControlEventTouchUpInside];
    [self.tableView reloadData];
}

-(void)butClicked:(UIButton *)but
{
    [self.delegate passindex:self.channel];
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return self.dataArr.count;
    
}
//重用池
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *reuseID = @"reuse";
    ShowMore_TBV_Cell *cell = [tableView dequeueReusableCellWithIdentifier:reuseID];
    if (cell == nil) {
        cell = [[ShowMore_TBV_Cell alloc]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:reuseID];
    }
    Blocks *block = [self.dataArr objectAtIndex:indexPath.row];
    cell.myLabel.text = block.name;
    cell.contentsArr = block.contents;
    cell.delegate = self;
    [cell.myCollectionVew reloadData];
    return cell;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    
    Blocks *block = [self.dataArr objectAtIndex:indexPath.row];
    if( block.contents.count % 2 == 0){
        return block.contents.count/2 * 160 * H + 80 * H;
    }else{
        return (block.contents.count/2 +1 ) * 160 * H + 80 * H;
    }
    
}


@end
